import {fileURLToPath, URL} from 'node:url'

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

import {viteMockServe} from 'vite-plugin-mock'
import {createHtmlPlugin} from "vite-plugin-html";
import path from 'path';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

// @ts-ignore
import {KeepAlivePatch} from "./keepalive-patch"

//修改Vue3的源码，解决KeepAlive不能删除Key的Bug
KeepAlivePatch();

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        vueJsx(),
        viteMockServe({
            mockPath: "mock",
            localEnabled: false,
            watchFiles: true
        }),
        createHtmlPlugin({
            /**
             * 需要注入 index.html ejs 模版的数据
             */
            inject: {
                data: {
                    NODE_ENV: process.env.NODE_ENV
                },
            },
        }),
        createSvgIconsPlugin({
            iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
            symbolId: '[name]'
        })
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        },
        extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
    },
    server: {
        proxy: {
            "/ssoserver": {
                target: "http://111.229.8.36:8088/ssoserver",
                //target: "http://localhost:11000/ssoserver",
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/ssoserver/, "/"),
                headers: {
                    "Host": "localhost:8088"
                },
            },
            "/webserver": {
                //target: "http://111.229.8.36:8088/webserver",
                target: "http://localhost:8080/webserver",
                changeOrigin: true,
                headers: {
                    "Host": "localhost:8088"
                },
                rewrite: (path) => path.replace(/^\/webserver/, "/"),
            },
        },
        port: 8088,
        base: './'
    },
})

